import matplotlib.pyplot as plt
import numpy as np
from scipy import signal

tmin = 0
tmax = 10
T = 0.01
t = np.arange(tmin, tmax, T)


def u(n):
   return np.where(n > 0, 1,0)


# 定义系统模型
num = np.array([0.0, 0.0, 1.0])
den = np.array([1.0, 5.0, 6.0])
system = signal.lti(num, den)

x = u(t)
# 手动计算公式
x2 = -1/2 * np.exp(-2 * t) + 1 / 3 * np.exp(-3 * t) + 1 / 6
# 零状态响应
tout, yout1, xout = signal.lsim(system, x, t)

plt.subplot(211)
plt.plot(tout, yout1)

plt.subplot(212)
plt.plot(t, x2)

plt.show()
